﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using AudioCore.Biz;
using AudioCore.Entity;

namespace AudioBook.AudioManagement
{
    public partial class LoginPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //txtUserName.Text = "chien";
            //txtPassword.Text = "********";
            //btnLogin_Click(sender, e);
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            AccountBiz bizAccount = new AccountBiz();
            AccountEntity enAccount = bizAccount.GetAccountByUserName(txtUserName.Text);
            if (enAccount != null && enAccount.Passwd.Equals(txtPassword.Text)
                && (enAccount.IsManager || enAccount.IsStaff))
            {
                Session[GUIConstants.Common.LOGIN_SESSION] = enAccount;
                Response.Redirect(GUIConstants.WebPage.CommonPage.HomePage);
            }
            else
            {
                lblError.Text = "Login fail. User name or password invalid";
            }
        }
    }
}
